//
//  YZDieOutCell.m
//  VET
//
//  Created by 刘文靖 on 2018/7/21.
//  Copyright © 2018年 YZ. All rights reserved.
//

#import "YZDieOutCell.h"
#import "YZDieOutModel.h"
#import "YZAutoItemModel.h"
#import "NSDate+YZDatePickView.h"
@interface YZDieOutCell()
@property (nonatomic, weak) UILabel *numberLabel; ///<编号
@property (nonatomic, weak) UILabel *dieoutNumDescLabel; ///<部分死亡
@property (nonatomic, weak) UILabel *typeLabel; ///<猪只/猪群 类别
@property (nonatomic, weak) UIButton *manageBtn; ///<管理按钮
@property (nonatomic, weak) UILabel *dieoutClassLabel; ///<分类
@property (nonatomic, weak) UILabel *dieoutSexLabel; ///<性别/死亡头数
@property (nonatomic, weak) UILabel *dieoutSexDescLabel; ///<性别/死亡头数
@property (nonatomic, weak) UILabel *dieoutTimeLabel; ///<死淘时间
@property (nonatomic, weak) UILabel *dieoutStateLabel; ///<死前状态
@end
@implementation YZDieOutCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self){
        self.contentView.backgroundColor = kColorWithHex(0xf5f5f5);
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        UIView *mainView = [[UIView alloc] init];
        mainView.layer.contents = (__bridge id)[UIImage imageNamed:@"card_background"].CGImage;
        [self.contentView addSubview:mainView];
        [mainView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.offset(12);
            make.bottom.offset(0);
            make.right.offset(-12);
        }];
        ///<编号
        UILabel *numberLabel = ({
            UILabel *label = [[UILabel alloc] init];
            label.textColor = kColorWithHex(0x434343);
            label.font = [UIFont fontWithName:@"SFCompactDisplay-Bold" size:18];
            [mainView addSubview:label];
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.offset(18);
                make.left.offset(26);
            }];
            label;
        });
        self.numberLabel = numberLabel;
        
        UILabel *dieoutNumDescLabel = ({
            UILabel *label = [[UILabel alloc] init];
            label.text = @"(部分死亡)";
            label.textColor = kColorWithHex(0x434343);
            label.font = [UIFont fontWithName:@"SFCompactDisplay-Bold" size:18];
            [mainView addSubview:label];
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.offset(18);
                make.left.mas_equalTo(numberLabel.mas_right).offset(5);
            }];
            label;
        });
        self.dieoutNumDescLabel = dieoutNumDescLabel;
        
        UILabel *typeLabel = ({
            UILabel *label = [[UILabel alloc] init];
            label.textColor = kColorWithHex(0x9B9B9B);
            label.font = [UIFont fontWithName:@"PingFangSC-Regular" size:12];
            [mainView addSubview:label];
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(numberLabel.mas_bottom).offset(6);
                make.left.mas_equalTo(numberLabel);
            }];
            label;
        });
        self.typeLabel = typeLabel;
        
        ///<管理按钮
        UIButton *manageBtn = ({
            UIButton *btn = [[UIButton alloc] init];
            [btn setTitle:@"管理" forState:UIControlStateNormal];
            [btn setTitleColor:kColorWithHex(0x32BE60) forState:UIControlStateNormal];
            btn.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
            [self.contentView addSubview:btn];
            [btn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.offset(-25);
                make.top.offset(25);
            }];
            btn;
        });
        self.manageBtn = manageBtn;
        
        ///<分类
        UILabel *dieoutClassDescLabel = [[UILabel alloc] init];
        dieoutClassDescLabel.text = @"分类";
        dieoutClassDescLabel.textColor = kColorWithHex(0x9B9B9B);
        dieoutClassDescLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
        [mainView addSubview:dieoutClassDescLabel];
        [dieoutClassDescLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.offset(86);
            make.left.mas_equalTo(numberLabel);
        }];
        
        UILabel *dieoutClassLabel = ({
            UILabel *label = [[UILabel alloc] init];
            label.textColor = kColorWithHex(0x9B9B9B);
            label.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
            [mainView addSubview:label];
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(dieoutClassDescLabel.mas_right).offset(5);
                make.top.mas_equalTo(dieoutClassDescLabel);
            }];
            label;
        });
        self.dieoutClassLabel = dieoutClassLabel;
        
        ///<性别/死亡头数
        UILabel *dieoutSexLabel = ({
            UILabel *label = [[UILabel alloc] init];
            label.textColor = kColorWithHex(0x9B9B9B);
            label.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
            [mainView addSubview:label];
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.offset(-50);
                make.top.mas_equalTo(dieoutClassLabel);
            }];
            label;
        });
        self.dieoutSexLabel = dieoutSexLabel;
        
        UILabel *dieoutSexDescLabel = ({
            UILabel *label = [[UILabel alloc] init];
            label.textColor = kColorWithHex(0x9B9B9B);
            label.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
            [mainView addSubview:label];
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.bottom.mas_equalTo(dieoutSexLabel);
                make.right.mas_equalTo(dieoutSexLabel.mas_left).offset(-5);
            }];
            label;
        });
        self.dieoutSexDescLabel = dieoutSexDescLabel;
        
        ///<死淘时间
        UILabel *dieoutTimeDscLabel = [[UILabel alloc] init];
        dieoutTimeDscLabel.text = @"死亡日期";
        dieoutTimeDscLabel.textColor = kColorWithHex(0x9B9B9B);
        dieoutTimeDscLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
        [mainView addSubview:dieoutTimeDscLabel];
        [dieoutTimeDscLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(dieoutClassDescLabel.mas_bottom).offset(12);
            make.left.mas_equalTo(dieoutClassDescLabel);
        }];
        
        UILabel *dieoutTimeLabel = ({
            UILabel *label = [[UILabel alloc] init];
            label.textColor = kColorWithHex(0x9B9B9B);
            label.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
            [mainView addSubview:label];
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(dieoutTimeDscLabel.mas_right).offset(5);
                make.top.mas_equalTo(dieoutTimeDscLabel);
            }];
            label;
        });
        self.dieoutTimeLabel = dieoutTimeLabel;
        
        ///<死前状态
        UILabel *dieoutStateDscLabel = [[UILabel alloc] init];
        dieoutStateDscLabel.text = @"死前状态";
        dieoutStateDscLabel.textColor = kColorWithHex(0x9B9B9B);
        dieoutStateDscLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
        [mainView addSubview:dieoutStateDscLabel];
        [dieoutStateDscLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(dieoutTimeDscLabel);
            make.left.mas_equalTo(dieoutSexDescLabel);
        }];
        
        UILabel *dieoutStateLabel = ({
            UILabel *label = [[UILabel alloc] init];
            label.textColor = kColorWithHex(0x9B9B9B);
            label.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
            [mainView addSubview:label];
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(dieoutStateDscLabel.mas_right).offset(5);
                make.top.mas_equalTo(dieoutStateDscLabel);
            }];
            label;
        });
        self.dieoutStateLabel = dieoutStateLabel;
        
        @weakify(self)
        [[self.manageBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            @strongify(self)
            if (self.delegate && [self.delegate respondsToSelector:@selector(cellDidClickManage:)]) {
                [self.delegate cellDidClickManage:self];
            }
        }];
        
    }
    return self;
}

- (void)setModel:(YZDieOutModel *)model{
    _model = model;
    self.numberLabel.text = model.dieOutNO;
    if ([model.type isEqualToString:@"swine"]) {
        self.typeLabel.text = @"猪只";
        self.dieoutNumDescLabel.hidden = YES;
    }else{
        self.typeLabel.text = @"猪群";
        self.dieoutNumDescLabel.hidden = NO;
    }
    self.dieoutClassLabel.text = model.dieoutClass.itemValue;
    if (model.dieoutSex) {
        self.dieoutSexLabel.text = model.dieoutSex.itemValue;
        self.dieoutSexDescLabel.text = @"性别";
    }else{
        self.dieoutSexLabel.text = [NSString stringWithFormat:@"%ld",(long)model.dieoutNum];
        self.dieoutSexDescLabel.text = @"死亡头数";
    }
    self.dieoutTimeLabel.text = [NSDate yz_getDateStringFromTimeInterval:model.dieoutTime format:@"yyyy-MM-dd"];
    self.dieoutStateLabel.text = model.dieoutState.itemValue;
    
    
}

@end
